package com.peng._05mvcboot01.user;

import com.peng._05mvcboot01.pojo.dto.UserDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户Controller
 * @Author peng
 * @Date 2024-04-20 11:49
 */
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @RequestMapping ("/login")
    @ResponseBody
    public String login(){

        return "login success";
    }

    /**
     * HttpServletRequest接收客户端的请求参数
     * @param request
     * @return
     */
    @RequestMapping("/reg")
    @ResponseBody
    public String register(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        return "username:" + username + ", password:" + password;
    }

    /**
     * 声明参数接收
     * 1. 请求参数名和控制器方法参数名一致
     * 2. 请求参数名和控制器方法参数名不一致，可以通过@RequestParam("username") String username来指定
     * @param username
     * @param oldPassword
     * @param newPassword
     * @return
     */
    @RequestMapping("/changepwd")
    public String changePassword(String userName, String oldPassword, String newPassword){
        return "username:" + userName + ", oldPassword:" + oldPassword + ", newPassword:" + newPassword;

    }

    @RequestMapping("/weChat")
    @ResponseBody
    public String weChat(UserDTO userDTO){
        String username = userDTO.getUsername();
        String password = userDTO.getPassword();
        return "username:" + username + ", password:" + password;
    }
}
